package com.dean.sql.service.impl;

import com.dean.sql.service.DeanSql;

/**
 * @ClassName DeanMysql
 * @Description
 * @Date 2022/1/1 13:57
 * @Created by dean
 */
public class DeanPgsql implements DeanSql {
    @Override
    public String getTableInfoSql() {
        return "select obj_description(b.oid,'pg_class') \"TABLE_COMMENT\" ,a.tablename \"TABLE_NAME\" from pg_tables a, pg_class b where a.tablename = b.relname and a.tablename = ?";

    }

    @Override
    public String getFieldInfoSql() {
        return "select a.\"COLUMN_NAME\",b.\"COLUMN_COMMENT\",a.\"DATA_TYPE\",a.\"DATA_LENGTH\",a.\"DATA_SCALE\",'N' \"PK_FLAG\" from \n" +
                "(select column_name \"COLUMN_NAME\",udt_name \"DATA_TYPE\",COALESCE(numeric_precision,character_maximum_length) \"DATA_LENGTH\" ,numeric_scale \"DATA_SCALE\",table_name from information_schema.columns where table_schema='public' order by ordinal_position) a,(SELECT c.attname \"COLUMN_NAME\",col_description(C.attrelid,C.attnum) \"COLUMN_COMMENT\",RELNAME table_name FROM PG_CLASS B ,pg_attribute c WHERE  c.ATTRELID= b.OID and  attnum>0) b where a.\"COLUMN_NAME\" = b.\"COLUMN_NAME\"  and a.table_name =b.table_name and a.table_name = ? ";
    }

    @Override
    public String getPageSql(String sql) {
        String exeSql = "select * from ("+sql+") t limit ?";
        return exeSql;
    }

    @Override
    public String covertTableName(String tableName) {
        return tableName.toLowerCase();
    }
}
